package com.ruoyi.student.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.student.domain.StudentCourses;
import com.ruoyi.student.service.IStudentCoursesService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 这是管理学生的选课表Controller
 * 
 * @author ruoyi
 * @date 2024-12-26
 */
@RestController
@RequestMapping("/student/courses")
public class StudentCoursesController extends BaseController
{
    @Autowired
    private IStudentCoursesService studentCoursesService;

    /**
     * 查询这是管理学生的选课表列表
     */
    @PreAuthorize("@ss.hasPermi('student:courses:list')")
    @GetMapping("/list")
    public TableDataInfo list(StudentCourses studentCourses)
    {
        startPage();
        List<StudentCourses> list = studentCoursesService.selectStudentCoursesList(studentCourses);
        return getDataTable(list);
    }

    /**
     * 导出这是管理学生的选课表列表
     */
    @PreAuthorize("@ss.hasPermi('student:courses:export')")
    @Log(title = "这是管理学生的选课表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, StudentCourses studentCourses)
    {
        List<StudentCourses> list = studentCoursesService.selectStudentCoursesList(studentCourses);
        ExcelUtil<StudentCourses> util = new ExcelUtil<StudentCourses>(StudentCourses.class);
        util.exportExcel(response, list, "这是管理学生的选课表数据");
    }

    /**
     * 获取这是管理学生的选课表详细信息
     */
    @PreAuthorize("@ss.hasPermi('student:courses:query')")
    @GetMapping(value = "/{studentId}")
    public AjaxResult getInfo(@PathVariable("studentId") Long studentId)
    {
        return success(studentCoursesService.selectStudentCoursesByStudentId(studentId));
    }

    /**
     * 新增这是管理学生的选课表
     */
    @PreAuthorize("@ss.hasPermi('student:courses:add')")
    @Log(title = "这是管理学生的选课表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StudentCourses studentCourses)
    {
        return toAjax(studentCoursesService.insertStudentCourses(studentCourses));
    }

    /**
     * 修改这是管理学生的选课表
     */
    @PreAuthorize("@ss.hasPermi('student:courses:edit')")
    @Log(title = "这是管理学生的选课表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StudentCourses studentCourses)
    {
        return toAjax(studentCoursesService.updateStudentCourses(studentCourses));
    }

    /**
     * 删除这是管理学生的选课表
     */
    @PreAuthorize("@ss.hasPermi('student:courses:remove')")
    @Log(title = "这是管理学生的选课表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{studentIds}")
    public AjaxResult remove(@PathVariable Long[] studentIds)
    {
        return toAjax(studentCoursesService.deleteStudentCoursesByStudentIds(studentIds));
    }
}
